<script type="text/javascript">
	//表格查询  
	function reloadProcessDefinition() {
		var params = processDefinition_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		processDefinition_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		processDefinition_list.datagrid('unselectAll');
		processDefinition_list.datagrid('uncheckAll');
	}
	
	function clearProcessDefinitionSearch() {
		setGridSearchParams('processDefinition_list','processDefinitionSearchForm',true,reloadProcessDefinition);
	}
	
	//根据条件查询
	function processDefinitionSearch() {
		setGridSearchParams('processDefinition_list','processDefinitionSearchForm',false,reloadProcessDefinition);
	}
	
	/**
	 * 激活
	 */
	function activeProcessDefinition() {
		 var rows = processDefinition_list.datagrid('getChecked');
		    if (rows&&rows.length>0){
		        $.messager.confirm('询问','你确认要激活吗?',function(r){
		        	if (r){
		            	var ids = "";
		            	for(var i=0; i<rows.length; i++)
		            	{
		            		if(!rows[i].suspended)
		            		{
		            			showMsg("请选择已挂起的记录.");
		            			return;
		            		}
		            		ids += rows[i].id+",";
		            	}
		            	
		                $.post('processdef.do?activeProcessDefinition',{ids:ids},function(result){
		                    if (result.success){
		                    	reloadProcessDefinition();    
		                    }
		                    showMsg(result.msg);
		                },'json');
		            }
		        });
		    }else {
		    	showMsg("请选择操作记录.");
		    }
	}
	/**
	 * 挂起
	 */
	function suspendedProcessDefinition() {
		var rows = processDefinition_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要挂起吗?',function(r){
	        	if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++)
	            	{
            			if(rows[i].suspended)
	            		{
	            			showMsg("请选择已激活的记录.");
	            			return;
	            		}
	            		ids += rows[i].id+",";
	            	}
	                $.post('processdef.do?suspendProcessDefinition',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadProcessDefinition();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function showProcessDefinition()
	{
		var rows = processDefinition_list.datagrid('getChecked');
	    if (rows&&rows.length>0)
	    {
	    	if(rows.length > 1)
	    	{
	    		showMsg("请选择操作1条记录.");
	    	}
	    	else
	    	{	
	    		id = rows[0].id;
	    		
	    		createFromWindowOptions({
					title:"查看流程图",
					maximizable:true,
					width:document.body.clientWidth,
					height:document.body.clientHeight,
					href:'processdef.do?graphProcessDefPage&ids='+id,
					callback:function(d) {
					},
					enableSaveButton:false
				});
	    	}
	    }
	    else 
	    {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function showXMLProcessDefinition()
	{
		var rows = processDefinition_list.datagrid('getChecked');
	    if (rows&&rows.length>0)
	    {
	    	if(rows.length > 1)
	    	{
	    		showMsg("请选择操作1条记录.");
	    	}
	    	else
	    	{	
	    		id = rows[0].id;
				props=window.open('processdef.do?consoleViewXml&processDefinitionId=' + id, 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=1366, height=768');
	    		
// 	    		createFromWindowOptions({
// 					title:"查看流程图",
// 					maximizable:true,
// 					width:document.body.clientWidth,
// 					height:document.body.clientHeight,
// 					href:'processdef.do?processXmlPage&ids='+id,
// 					callback:function(d) {
// 						alert(123);
// 					},
// 					enableSaveButton:false
// 				});
	    	}
	    }
	    else 
	    {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	/**
	 * 编辑用户信息
	 */
	function editProcessDefinition() {
		var rows = processDefinition_list.datagrid('getChecked');
	    if (rows&&rows.length>0)
	    {
	    	if(rows.length > 1)
	    	{
	    		showMsg("请选择操作1条记录.");
	    	}
	    	else
	    	{	
	    		id = rows[0].id;
	    		createFromWindow("更新流程定义", 'processdef.do?beforeUpdateProcess&processDefinitionId='+id, "processdef.do?updateProcess",
				function(data) {
					reloadProcessDefinition();
				});
	    	}
	    }
	    else 
	    {
	    	showMsg("请选择操作记录.");
	    }
	}
	
</script>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<@eu.datagrid id="processDefinition_list" toolbar="#processDefinitionList_search"
		idField="id" url="processdef.do?listProcessDefinitions"
		rownumbers="true" onDblClickRow="onDblClickProcessDefinitionRow(rowIndex,
		rowData)" item="com.xdtech.oa.bpm.vo.ProcessDefinitionItem"/>

		<div id="processDefinitionList_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="processDefinitionSearchForm">
					<!-- 防止form表单里只有一个text元素时候，按enter键自动提交问题 -->
					<input style="display:none" />
					<table>
						<tr>
						<td class="tbLabel">名称：</td>
							<td><input class="easyui-validatebox textbox" name="name" style="width: 150px" />
						</td>
						<td rowspan="2">
							<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="processDefinitionSearch()"/>
 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearProcessDefinitionSearch()"/>
					 	</td>
						</tr>
					</table>
				</form>

			</div>
			<div id="processDefinition_toolbar" style="height: auto">
				<@eu.linkbutton
				showName="激活" shiro="bmp:processDefinition:active" iconCls="icon-ok"
				onclick="activeProcessDefinition()"/>
				
				<@eu.linkbutton
				showName="挂起" shiro="bmp:processDefinition:suspended" iconCls="icon-no"
				onclick="suspendedProcessDefinition()"/>
				
				<@eu.linkbutton showName="流程图" shiro="bmp:processDefinition:showpro"
				iconCls="icon-add" onclick="showProcessDefinition()"/> 
				
				<@eu.linkbutton
				showName="查看XML" shiro="bmp:processDefinition:showxml" iconCls="icon-remove"
				onclick="showXMLProcessDefinition()"/>  
				
				<@eu.linkbutton
				showName="diagram-viewer" shiro="bmp:processDefinition:diagramviewer" iconCls="icon-remove"
				onclick="showMsg('尽请期待.');"/>  
				
				<@eu.linkbutton
				showName="编辑" shiro="bmp:processDefinition:edit" iconCls="icon-edit"
				onclick="editProcessDefinition()"/>  
				
				
				<@eu.linkbutton showName="刷新"
				shiro="bmp:processDefinition:refresh" iconCls="icon-reload"
				onclick="reloadProcessDefinition()"/></div>
		</div>
	</div>
</div>